<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
    initial-scale=1,minimum-scale=1,maximum-scale=1,
    user-scalable=no,viewport-fit=cover">
    <title>注册</title>
</head>

<body>
    <form id="registForm">
        <div>
            <label>用户名<input type = "text" name = "name"></input></label>
        </div>
        <div>
            <label>密码<input type = "password" name = "password"></input></label>
        </div>
        <div>
            <button type="submit">注册</button>
        </div>
    </form>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
        const $form = $('#registForm')
        $form.on('submit', (e) => {
            e.preventDefault()
            const name = $form.find('input[name=name]').val()
                // console.log(1)
            const password = $form.find('input[name=password]').val()
            console.log(name, password)
            $.ajax({
                method: 'POST',
                url: 'regist',
                contentType: 'text/json;charset=UTF-8',
                data: JSON.stringify({
                    name,
                    password
                })
            }).then(() => {
                alert('注册成功')
                location.href = '/sign_in.html'
            }, () => {})
        })
    </script>

</body>

</html>